﻿#region Using's

using System;

#endregion

namespace MyUtils
{
	public static class DateTimeNow
	{
		static DateTime _configured;

		static bool useConfigured
		{
			get { return _configured != default(DateTime); }
		}

		public static DateTime Local
		{
			get { return useConfigured ? _configured.ToLocalTime() : DateTime.Now; }
		}

		public static DateTime Utc
		{
			get { return useConfigured ? _configured.ToUniversalTime() : DateTime.UtcNow; }
		}

		public static void Stub(DateTime dtUtc)
		{
			if (dtUtc.Kind == DateTimeKind.Unspecified)
			{
				dtUtc = new DateTime(dtUtc.Ticks, DateTimeKind.Utc);
			}
			_configured = dtUtc.ToUniversalTime();
		}

		public static void Stub(TimeSpan dt)
		{
			_configured = Utc.Add(dt);
		}
	}
}